<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
        }
        .container {
            width: 80%;
            max-width: 400px;
            margin: 50px auto;
            padding: 20px;
            background: #fff;
            border: 1px solid #ddd;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        header {
            background: #333;
            color: #fff;
            padding: 20px;
            text-align: center;
        }
        form {
            margin-top: 20px;
        }
        form h2 {
            color: #333;
            margin-bottom: 20px;
        }
        form label {
            display: block;
            margin-bottom: 5px;
        }
        form input[type="text"],
        form input[type="password"],
        form input[type="email"] {
            width: calc(100% - 20px);
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ddd;
        }
        form input[type="button"] {
            width: 100%;
            padding: 10px 20px;
            background: #333;
            color: #fff;
            border: none;
            cursor: pointer;
        }
        form input[type="button"]:hover {
            background: #444;
        }
        .captcha {
            text-align: center;
            margin-bottom: 10px;
        }
        .captcha img {
            border: 1px solid #ddd;
            width: 100px;
            height: 40px;
        }
        .footer {
            background: #333;
            color: #fff;
            text-align: center;
            padding: 10px 0;
            position: relative;
            bottom: 0;
            width: 100%;
        }
        .footer p {
            margin: 0;
        }
    </style>
</head>
<body>
    <header>
        <h1>订阅者注册</h1>
    </header>
    <div class="container">
        <form action="#" method="post">
            <h2>创建您的账户</h2>
            <label for="username">用户名：</label>
            <input type="text" id="username" name="username" required>

            <label for="email">邮箱：</label>
            <input type="email" id="email" name="email" required>

            <label for="password">密码：</label>
            <input type="password" id="password" name="password" required>

            <label for="confirm_password">确认密码：</label>
            <input type="password" id="confirm_password" name="confirm_password" required>

            <div class="captcha">
                <label for="captcha">验证码：</label>
                <img id="captcha" src="./img/captcha.png" alt="验证码">
            </div>
            <input type="text" id="captchacode" name="captcha" placeholder="输入验证码" required>

            <input type="button" class="register" value="注册">

            <p>已经有账户? <a href="login.html">登录</a></p>
        </form>
    </div>
    <footer>
        <p>版权所有 © 2024 用户管理系统</p>
    </footer>
</body>
<script src="js/jquery-3.7.1.min.js"></script>
<script>
    $(function($){
        let captcha = document.querySelector("#captcha");
        // 添加一个随机数 防止请求识别不出来
        captcha.onclick = function () {
            this.src = "http://www.dlrb.com/woniu/common/captcha.php?t=" + Math.random();  // 点击图片刷新验证码
        }
        $(".register").click(function(){
            $.ajax({
                url: "http://www.dlrb.com/woniu/server/register.php",
                type: "post",
                dataType: "json",
                async: false,
                data: {
                    username:$("#username").val(),
                    mail:$("#email").val(),
                    password:$("#password").val(),
                    confirm_password:$("#confirm_password").val(),
                    captcha:$("#captchacode").val(),
                },
                success: function (resp) {
                    if (resp.code == 200){
                        location = "users.php"
                    }else {
                        alert(resp.message)
                    }
                },
                error: function (err) {
                    console.log(err)
                }
            })
        })
    })
</script>
</html>